from pandas import read_excel, to_timedelta
from datetime import datetime
from numpy import ceil
import importlib

from pandas.core.frame import DataFrame

from .factories import factory as fy
from .exsheet import exblock_in_sheet
from .cnamount import amount_converter

class data_reader:

    fac_map:dict = {
        None : 'corpself',
        '大冶华鑫': 'huaxing',
        '山东闽源': 'minyuan',
        '贵阳特钢': 'guigang',
        '上饶台鑫': 'taixing',
        '河北新金': 'xinjin',
        '欧冶链金': 'oyelianjin',
    } # 通过钢厂名称，映射对应的 factory 类名

    factory:fy = None

    def __init__(self, data_file, idx=0, factory_name:str='大冶华鑫', receipt:str='入仓单')->None:
        self.datafile = data_file
        self.idx = idx
        self.factory_name = factory_name
        self.receipt = receipt
        self.get_factory()
 
    @property
    def tidy_data(self):       
        self.factory.read_data(self.datafile, self.idx)
        return self.factory.tidy_data

    def get_oto_loc(self,receipt:str)->dict:
        
        return self.factory.get_oto_loc(receipt)
    
    @property
    def mtm_loc(self):
        return self.factory.mtm_loc
   
    def get_factory(self):
        factory_class_name = self.fac_map[self.factory_name]
        
        factory_class = getattr(importlib.import_module("yolib.factories"), factory_class_name)
        factory_instance = factory_class()
        self.factory = factory_instance
        